<!-- Template for views -->
<?php html::docType() ?>
<html>
<head>
	<?php html::head() ?>
	
<link href="../css/style.css" rel="stylesheet" type="text/css" />

</head>
<body>
<div id="container">
		<?php
			html::navBar2();
				html::flash();
		?>

<!--	<div id="header">-->
<!--		<h1>Where Is My Beer?</h1>-->
<!--		<div id="nav">-->
<!--			<ul>-->
<!--				<li><a href="#">Home</a></li>-->
<!--				<li><a href="#">Beers</a></li>-->
<!--				<li><a href="#">Venues</a></li>-->
<!--				<li><a href="#">Register</a></li>-->
<!--				<li><a href="#">Login</a></li>-->
<!--			</ul>-->
<!--		</div>-->
<!--	</div>-->
	<div id="content">
		<div class="section" id="main">
			<div class="section-title">
				<h1 class="page-name">Current Offers in Melbourne</h1>
				<span class="title-sub"><a href="router.php?c=offer&a=create">Create
new</a></span>
			</div>
				<?php 
					if(isset($view->request)){
						echo "<div class='showing-results'><h2 class=showing-results'>
						Results for: Beer > ". (!isset($view->request["beer_name"]) || 
						$view->request["beer_name"]=='' ? "Any":$view->request["beer_name"]).", 
						Price > ".(!isset($view->request["price"]) || $view->request["price"]=='' 
						? "Any":$view->request["price"])." and Suburb >". (!isset($view->request['suburb'])
						||$view->request['suburb'] == '' ? "Any":$view->request['suburb']) . "</h2></div>";
					}

		$markers="";
		$char=65;
		
		foreach($view->offers as $offer){
			$price = '$'.$offer['price'];
			$ratingElem = getRatingElement("offer",$offer['venue_id'],$offer["rounded_venue_rate"]);
			$repeats = getOfferRepeatDays($offer['repeats']);
			$timeFrom = split(":",$offer["time_from"]);
			$timeFrom = "$timeFrom[0]:$timeFrom[1]";
			$timeTo = split(":",$offer["time_to"]);
			$timeTo = "$timeTo[0]:$timeTo[1]";
			$street=urlencode($offer['street']);
			$suburb=urlencode($offer['suburb_name']);
			$markerLetter = chr($char++);
			$marker = "&markers=color:blue|label:$offer[price]|$offer[street]+$offer[suburb_name]";
			$marker = "&markers=color:blue|label:$markerLetter|$street+$suburb+VIC+Australia";
//			$marker = "&markers=color:blue|label:$offer[price]|$street+$suburb";
//			$marker = "&markers=icon:http://chart.apis.google.com/chart?chst=d_bubble_icon_text_small&chld=ski|bb|Wheeee!|FFFFFF|000000|$street+$suburb";
			$markers = "$markers $marker";

echo <<<EOB
			<div class="offer-result">
				<div class="offer-price">{$price}</div>
				<div class="offer-size-picture">
            		<img src="../img/beer_sizes/{$offer['size_id']}.gif" height="60"/>
        		</div>
				<div class="offer-details">
					<div class="offer-venuename">
						<span class="venue-name"><a href="router.php?c=venue&a=view&id={$offer['venue_id']}">{$offer["venue_name"]}</a>
						{$ratingElem}
					</div>
					
						
					
					<div class="offer-description">
						<div>
            				<span class="offer-beers">
EOB;
							$a=array();
							foreach($offer["beers"] as $beer){
								$a[]= "<a href='router.php?c=beer&a=get&id=$beer[id]'>$beer[name]</a>";

							}
							echo implode(", ", $a);
echo <<<EOB
							</span>
		    			</div>
			    		<div>
	            			{$repeats}&nbsp
	        				From: {$timeFrom} to: {$timeTo}
	                    </div>

	                    <div>
            				Marker in Map: $markerLetter
            				<span style="float:right" class="read-more">Read More</span>
           				</div>
           		
           				<div style="display:none">
           					<div>
           						<b>Vadid From {$offer['date_from']} To {$offer['date_to']}</b>
           					</div> 
           					<div>
           						<b>Details:</b><br/>
           						{$offer['description']}
           					</div>
           				</div>
					</div>
				</div>
				
			</div>
EOB;
		}
echo <<<EOB
		<div class="pagination">
 			<a href="{$prevLink}">Prev</a>&nbsp;|&nbsp;
			<a href="{$nextLink}">Next</a>
        </div>
	</div>
		<div id="side">
			<div class="section" id="search">
				<div class="section-title">
					<h3>Search</h3>
					
				</div>
				<form action="router.php" method="GET">
					<input type="hidden" name="c"
            			value="offer"> <input type="hidden" name="a" value="find"> 
					<input type="text" id="search-beer" name="beer_name" title="Beer Name" />
					<input type="text" id="search-price" name="price" title="Max Price" />
					<select id="search-suburb" name="suburb">
						<option value="">Suburb</option>
						<option value="">All</option>
EOB;
							foreach ($view->suburbs as $suburb) {
								echo "<option value='{$suburb[name]}'>{$suburb['name']}</option>";
							}
echo <<<EOB
					</select>
					<input type="submit" id="search-button" value="Search" class="button" />
				</form>
			</div>
			<div class="section" id="map-side">
				<div class="section-title">
					<h3>Map</h3>
					
				</div>
				<div class="offer-list-map">
					<img src="http://maps.google.com/maps/api/staticmap?size=300x300&maptype=roadmap
					{$markers}&sensor=false"/>
            	</div>
			</div>
		</div>
	</div>
	
EOB;
html::footer2();
?>
</div>
</body>
</html>